<template>
    <div>
        <Tabs value="department" type="card" :animated="true">
            <TabPane label="部门审批监测" icon="md-stats" name="department"
                     :linkOption="{component:'projects/afs-core-business/pages/case/approve/aging-monitor/department-monitor',
                                 isFull:true,pageTitle:'部门审批监测'}">
                <Spin fix size="large" v-if="loading">
                    <slot name="loading"></slot>
                </Spin>
                <aging-monitor :data-list="newCarList" :type="type" ref="newCarTable" @on-end-summary="getSum">
                    <div slot="header">
                        <Alert><b>部门审批监测</b><Button icon="md-refresh" ghost type="primary" @click="refresh" style="margin:5px"></Button></Alert>
                    </div>
                </aging-monitor>
                <aging-monitor :data-list="oldCarList" ref="oldCarTable" @on-end-summary="getSum" />
                <Table :columns="columns" :data="totalData" ref="totalTable"/>
            </TabPane>
        </Tabs>
    </div>
</template>

<script>
    import {listByDepartment} from "../../../../api/afs-case/aging-monitor/agingMonitor";
    import AgingMonitor from "./aging-monitor";
    import {deepCopy} from "../../../../../../components/iview/utils/assist";
    export default {
        name: "department-monitor",
        components: {AgingMonitor},
        data(){
            return{
                newCarList:[],
                oldCarList:[],
                totalData:[],
                type:"department",
                loading:false,
                columns:[
                    {
                        type: "index",
                        minWidth: 65,
                        fixed:"left",
                        key:"index",
                        align: "center"
                    },
                    {
                        title: "业务类型",
                        fixed:"left",
                        minWidth: 85,
                        key: "businessType",
                        align: "center"
                    },
                    {
                        title: "姓名",
                        fixed:"left",
                        minWidth: 90,
                        tooltip:true,
                        key: "realName",
                        align: "center"
                    },
                    {
                        title: "岗位状态",
                        minWidth: 85,
                        key: "postStatus",
                        fixed:"left",
                        align: "center"
                    },
                    {
                        title: "岗位",
                        minWidth: 90,
                        tooltip:true,
                        key: "jobPosition",
                        align: "center"
                    },
                    {
                        title: "总计",
                        minWidth: 70,
                        key: "total",
                        align: "center"
                    },
                    {
                        title: "待审核",
                        minWidth: 75,
                        key: "numWaitCheck",
                        align: "center"
                    },
                    {
                        title: "暂停",
                        minWidth: 65,
                        key: "numParse",
                        align: "center"
                    },
                    {
                        title: "修订回复",
                        minWidth: 85,
                        key: "numReviseReply",
                        align: "center"
                    },
                    {
                        title: "建议核准",
                        minWidth: 85,
                        key: "numCheck",
                        align: "center"
                    },
                    {
                        title: "建议拒绝",
                        minWidth: 85,
                        key: "numReject",
                        align: "center"
                    },
                    {
                        title: "建议附条件",
                        minWidth: 100,
                        key: "numCondition",
                        align: "center"
                    },
                    {
                        title: "撤回",
                        key: "numCallback",
                        minWidth: 65,
                        align: "center"
                    },
                    {
                        title: "资产变更",
                        minWidth: 85,
                        key: "numAssertChange",
                        align: "center"
                    },
                    {
                        title: "欺诈调查",
                        minWidth: 85,
                        key: "numFraudInspect",
                        align: "center"
                    },
                    {
                        title: "库存超期",
                        minWidth: 85,
                        key: "numRepertoryOverdue",
                        align: "center"
                    },
                    {
                        title: "复议",
                        minWidth: 65,
                        key: "numReview",
                        align: "center"
                    },
                    {
                        title: "修订暂停",
                        minWidth: 85,
                        key: "todayNumReviseParse",
                        align: "center"
                    },
                    {
                        title: "已处理",
                        minWidth: 75,
                        key: "todayNumProcess",
                        align: "center"
                    },
                    {
                        title: "已核准",
                        minWidth: 75,
                        key: "todayNumAlreadyCheckFinal",
                        align: "center"
                    },
                    {
                        title: "附条件核准",
                        minWidth: 100,
                        key: "todayNumAlreadyConditionFinal",
                        align: "center"
                    },
                    {
                        title: "已拒绝",
                        minWidth: 75,
                        key: "todayNumAlreadyRejectFinal",
                        align: "center"
                    },
                    {
                        title: "出结果",
                        minWidth: 75,
                        key: "todayNumAlreadyEnd",
                        align: "center"
                    },
                    {
                        title: "平均时效",
                        minWidth: 85,
                        key: "agingAvg",
                        align: "center"
                    }
                ],
            }
        },
        methods:{
            queryMonitorsByDepartment(){
                this.loading = true;
                listByDepartment().then(res=>{
                    this.newCarList = res.data.newCar;
                    this.oldCarList = res.data.oldCar;
                    this.calSum();
                }).finally(()=>{
                    this.loading = false;
                });
            },
            refresh(){
                this.queryMonitorsByDepartment();
            },
            calSum(){
                this.totalData = [];
                setTimeout(()=>{
                    let sumData = {};
                    let newCarSum = this.$refs['newCarTable'].finalSum;
                    let oldCarSum = this.$refs['oldCarTable'].finalSum;
                    sumData.index = "总计";
                    Object.getOwnPropertyNames(newCarSum).forEach(key=>{
                        if(!isNaN(newCarSum[key])){
                            sumData[key] = newCarSum[key];
                        }
                    })

                    Object.getOwnPropertyNames(newCarSum).forEach(key=>{
                        if(!isNaN(newCarSum[key])){
                            sumData[key] += oldCarSum[key];
                        }
                    })

                    this.totalData.push(sumData);
                },150)
            },
            getSum(totalSum){
            }
        },

        created() {
            this.queryMonitorsByDepartment();
        }
    }
</script>

<style scoped>

</style>
